package com.example.validproject.controller;

import com.example.validproject.entity.Person;
import com.example.validproject.protocol.Result;
import com.example.validproject.valid.ParamValid;
import com.example.validproject.valid.UpdateGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kh
 * Created by on  2021-09-27 15:18
 */
@RestController
public class PersonController {

    @PostMapping("saveStudent")
    public Result saveStudent(@RequestBody @Validated({ParamValid.Student.class}) Person person) {
        person.setId(System.currentTimeMillis());
        return Result.success(person);
    }

    @PostMapping("saveTeacher")
    public Result saveTeacher(@RequestBody @Validated({ParamValid.Teacher.class}) Person person) {
        person.setId(System.currentTimeMillis());
        return Result.success(person);
    }

    @PostMapping("savePerson")
    public Result savePerson(@RequestBody @Validated({ParamValid.Teacher.class,ParamValid.Student.class}) Person person) {
        person.setId(System.currentTimeMillis());
        return Result.success(person);
    }
    @PutMapping("updatePerson")
    public Result updatePerson(@RequestBody @Validated({UpdateGroup.class}) Person person) {
        person.setId(System.currentTimeMillis());
        return Result.success(person);
    }
}
